define(function(require){

    require('../../../c/base/index');

    require('../../../c/nav/index');


    var syncOrgData = {
        init : function() {
            //初始化菜单选中效果
            $(".fa-circle-o").each(function(){
                if($(this).parents("a").text() == "组织架构数据同步"){
                    $(this).parents("a").parents("li").addClass("active");
                }
            });
            this.bindEvent();
        },

        bindEvent : function() {
            var self = this;

            self.block = false;
            $("#get").click(function () {
                if(self.block==false) {
                    CRM.request({
                        url: CRM.getOuterUrl("/org/syncEmpData.do"),
                        timeout: 3000,
                        type: 'get',
                        error: function (error) {
                            $("#showResults").html('<div class="alert alert-danger">' + error
                                + '</div>');
                        },
                        success: function (data) {
                            $("#showResults").html('');
                            CRM.showDialog(data.message);
                        },
                        complete: function (XMLHttpRequest, status) { //请求完成后最终执行参数
                            if (status == 'timeout') {//超时,status还有success,error等值的情况
                                var dis = "请您稍等，数据正在同步中，大概需要两分钟左右";
                                $("#showResults").html('<div class="alert alert-danger">' + dis
                                    + '</div>');
                            }
                        }
                    });
                    self.block = true;
                    $('#get').attr("disabled","disabled");
                    setTimeout(function () {
                        self.block = false;
                        $('#get').removeAttr("disabled");
                    }, 30000);
                }
            });
        }
    };

    syncOrgData.init();
});

